package cn.wenhaha.app.config;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.json.JSONUtil;
import cn.wenhaha.common.db.bean.SysUser;

import javax.servlet.*;
import java.io.IOException;

/**
 * 数据源插件过滤器
 * --------
 *
 * @author ：wyndem
 * @Date ：Created in 2022-08-04 23:00
 */

public class DataSourcePluginFilter implements Filter {



    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {

        if (StpUtil.isLogin()){
            Object loginId = StpUtil.getLoginId();
            SysUser sysUser =(SysUser) StpUtil.getSession().get("info");
            servletRequest.setAttribute("id", Long.valueOf(loginId.toString()));
            servletRequest.setAttribute("info", JSONUtil.toJsonStr(sysUser));
        }
        filterChain.doFilter(servletRequest, servletResponse);

    }


}
